package com.wolfalpha.utron.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ListView;

import com.wolfalpha.utron.R;
import com.wolfalpha.utron.activity.base.BaseNormalActivity;
import com.wolfalpha.utron.adapter.ItemProjectAttentionedAdapter;
import com.wolfalpha.utron.bean.UserBaseInfo;
import com.wolfalpha.utron.service.ProjectService;
import com.wolfalpha.utron.service.impl.ProjectServiceImpl;
import com.wolfalpha.utron.ui.UIHelper;
import com.wolfalpha.utron.utils.ThreadPoolUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目关注用户列表界面
 * <p/>
 * Created by luodon on 15/8/31.
 */

public class ProjectAttentionedActivity extends BaseNormalActivity {

    private ListView lvUsers;        //用户列表控件

    private int pId = 0;

    private ProjectService projectService;

    private List<UserBaseInfo> baseInfos = new ArrayList<UserBaseInfo>();

    private ItemProjectAttentionedAdapter attentionedAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle bundle = getIntent().getExtras();
        if (bundle == null || !bundle.containsKey("pId")) {
            finish();
        }
        pId = bundle.getInt("pId");

        setContentView(R.layout.activity_project_attentioned);
        projectService = new ProjectServiceImpl();

        intiView();
        loadData();
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            attentionedAdapter.setData(baseInfos);
        }
    };

    /**
     * 加载数据
     */
    private void loadData() {


        ThreadPoolUtils.execute(new Runnable() {
            @Override
            public void run() {
                baseInfos = projectService.getAttentions(pId);
                if (baseInfos != null) {
                    handler.sendEmptyMessage(0);
                }
            }
        });


    }


    private final static int IPUT_SHOW = 1;     //输入法打开
    private final static int IPUT_DISMISS = 2; //输入法隐藏
    private final int LOAD_MORE = 3;    //加载更多
    private final int LOAD_REFRESH = 4; //刷新

    private boolean ipuitShowing = false;

    private boolean inputIsShowing = false;

    private int page = 1;

    /**
     * 初始化界面
     */
    private void intiView() {
        setTvTitle("已关注的用户");
        lvUsers = (ListView) findViewById(R.id.wl_project_attentioned);
        attentionedAdapter = new ItemProjectAttentionedAdapter(ProjectAttentionedActivity.this, baseInfos);
        lvUsers.setAdapter(attentionedAdapter);

        attentionedAdapter.setOnHeadClickListener(new ItemProjectAttentionedAdapter.OnHeadClickListener() {
            @Override
            public void clickHead(int id) {
                Bundle bundle = new Bundle();
                bundle.putInt("userId", id);
                UIHelper.showActivity(ProjectAttentionedActivity.this, UserInfoActivity.class, bundle);
            }
        });
    }

}
